#!/bin/sh
#
DAEMON=/usr/sbin/pppd
PIDFILE=/var/run/ppp0.pid

# define the interface used for the connection
DAEMON_OPTS=@PPPD_INTF@

case "${1}" in
	start)
		if [ -e $PIDFILE ]; then
			echo "pppd already running"
			exit 1
		fi
		echo "Starting pppd..."
		$DAEMON $DAEMON_OPTS || echo "failed"
		;;

	stop)
		if [ ! -e $PIDFILE ]; then
			echo "pppd not running"
			exit 1
		fi
		echo "Stopping pppd..."
		kill -s SIGTERM `cat $PIDFILE` || echo "failed"
		;;

	restart)
		if [ ! -e $PIDFILE ]; then
			echo "pppd not running"
			exit 1
		fi
		echo "Restarting pppd..."
		kill -s SIGTERM `cat $PIDFILE` || echo "failed"
		sleep 1
		$DAEMON $DAEMON_OPTS || echo "failed"
		;;

	status)
		if [ -e $PIDFILE ]; then
			echo "pppd running"
		else
			echo "pppd not running"
		fi
		;;

	hangup)
		if [ ! -e $PIDFILE ]; then
			echo "pppd not running"
			exit 1
		fi
		echo "pppd hanging up"
		kill -s SIGHUP `cat $PIDFILE` || echo "failed"
		;;

	*)
		echo "Usage: ${0} {start|stop|restart|status|hangup}"
		exit 1
		;;
esac
